package com.starblink.post.topicdetail.adapter

import android.view.ViewGroup
import com.starblink.android.basic.adapter.BaseVH
import com.starblink.android.basic.ext.commContext
import com.starblink.android.basic.extension.navigationTo
import com.starblink.android.basic.util.post.PostListDataHolder
import com.starblink.basic.route.RoutePage
import com.starblink.rocketreserver.fragment.PostF
import view.post.PostCardView

class TopicPostCardCell(
    parent: ViewGroup,
    private val pageEle: Int,
    private val topicId: String?,
    private val searchPage: Int,
    private val postList: ArrayList<PostF>
) : BaseVH<PostF>(PostCardView(parent.context)) {

    private val cardView = itemView as PostCardView

    override fun onBind(post: PostF, position: Int) {
        cardView.bindPost(post, position, spmPageValue = pageEle) {
            PostListDataHolder.getInstance().setList(postList)
            commContext().navigationTo(if (post.contentType == "1") RoutePage.Post.PAGE_PIC else RoutePage.PostVideo.PAGE_VIDEO) {
                withString(RoutePage.Post.POST_ID, post.id)
                withInt(RoutePage.Post.ARG_SCENE, RoutePage.Post.SCENE.TOPIC.value)
                withObject(RoutePage.Post.POST, post)
//                withObject(RoutePage.Post.POST_LIST, postList)
                withInt(RoutePage.Post.POST_PAGE, searchPage)
                withString(RoutePage.Post.TOPIC_ID, topicId)
                withInt("index", position)
            }
        }
    }
}